<?php 
	Class Hotelroomprice extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model('model_hotelroomprice');	
			$this->load->model('model_hotelroom');	
			$this->load->model('model_hotel');	
		}	
		
		public function index(){
			if(isset($_GET['hotelid']) && isset($_GET['roomid'])){
				$data['hotel']=$this->model_hotel->getdata(intval($_GET['hotelid']));	
				$data['room']=$this->model_hotelroom->getdata(intval($_GET['roomid']));	
				$data['data']=$this->model_hotelroomprice->getallbyroomid(intval($_GET['roomid']));
			}
			
			$data['template']='hotel/hotel_room_price';
			$this->load->view('layout',$data);
		}
		
		public function edit(){
			if(isset($_GET['id'])){
				$data['detail']	=$this->model_hotelroomprice->getdata(intval($_GET['id']));
			}else $data['detail']=NULL;
			
			$data['template']='hotel/hotelroomprice_edit';
			$this->load->view('layout',$data);
		}
		
		public function insert(){
			$data['price']=$_POST['price'];	
			$data['oldprice']=$_POST['oldprice'];
			$data['priceforchild']=$_POST['priceforchild'];
			$data['fromdate']=date("Y-m-d",strtotime($_POST['fromdate']));
			$data['todate']=date("Y-m-d",strtotime($_POST['todate']));
			$data['status']=$_POST['status'];
			$data['extra']=$_POST['extra'];
			$data['roomid']=$_GET['roomid'];
			$this->model_hotelroomprice->add($data);
			header('Location: '.base_url().'admin/hotelroomprice/index?hotelid='.$_GET['hotelid'].'&roomid='.$_GET['roomid']);
		}
		
		public function update(){
			if(isset($_GET["id"])){
				$data['price']=$_POST['price'];	
				$data['oldprice']=$_POST['oldprice'];
				$data['priceforchild']=$_POST['priceforchild'];
				$data['fromdate']=date("Y-m-d",strtotime($_POST['fromdate']));
				$data['todate']=date("Y-m-d",strtotime($_POST['todate']));
				$data['status']=$_POST['status'];
				$data['extra']=$_POST['extra'];
				$data['roomid']=$_GET['roomid'];
				$this->model_hotelroomprice->update($data,intval($_GET['id']));
				header('Location: '.base_url().'admin/hotelroomprice/index?hotelid='.$_GET['hotelid'].'&roomid='.$_GET['roomid']);
			}	
		}
		
		public function delete(){
			if(isset($_GET["id"])){
				$this->model_hotelroomprice->del(intval($_GET['id']));	
				header('Location: '.base_url().'admin/hotelroomprice/index?hotelid='.$_GET['hotelid'].'&roomid='.$_GET['roomid']);
			}	
		}
		
		public function changestatus(){		
			if(isset($_GET["status"])){
				$data['status']=intval($_GET['status']);
				$this->model_hotelroomprice->update($data,intval($_GET["id"]));
				header('Location: '.base_url().'admin/hotelroomprice/index?hotelid='.$_GET['hotelid'].'&roomid='.$_GET['roomid']);
			}
		}
	}
?>